/**
 * This file is part of the CAKIS project.
 * 
 * Copyright (c) 2009-2010 - Florian Arndt, Christian Kerl
 * 
 * @license GNU Lesser General Public License v3 <http://www.opensource.org/licenses/lgpl-3.0.html>
 * @since   20.04.2010
 * @version SVN: $Id: InitialStockUnitLoader.java 84 2010-04-26 17:45:40Z christian-kerl@web.de $
 */
package org.cakis.server.model.loader;

import org.cakis.server.Names;
import org.cakis.server.model.StockUnit;
import org.cakis.server.model.repository.StockUnitRepository;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.*;

/**
 * InitialStockUnitLoader
 *
 * @author Christian Kerl
 */
@Name(Names.InitialStockUnitLoader)
@Scope(ScopeType.APPLICATION)
@Startup
public class InitialStockUnitLoader {
    private StockUnitRepository repository;

    @In(Names.StockUnitRepository)
    public void setRepository(StockUnitRepository repository) {
        this.repository = repository;
    }

    @Create
    public void loadStockUnits() {
        repository.store(createStockUnit("Centiliter", "cl"));
        repository.store(createStockUnit("Liter", "l"));

        repository.store(createStockUnit("Gramm", "g"));
        repository.store(createStockUnit("Kilogramm", "kg"));

        repository.store(createStockUnit("Stück", "Stk"));
    }

    private StockUnit createStockUnit(String name, String symbol) {
        StockUnit result = new StockUnit();
        result.setName(name);
        result.setSymbol(symbol);

        return result;
    }
}
